const createError = require('http-errors')
const fs = require('fs')

const errorRouter = (req, res, next) => {
    next(createError(404))
}

const errorHandler = (err, req, res, next) => {
    res.locals.message = err.message
    res.locals.error = req.app.get('env') === 'development' ? err : {};

    // render the error page
    res.status(err.status || 500)
    const errorPage = fs.readFileSync('./views/404.html')
    res.end(errorPage)
}

module.exports = {
    errorRouter,
    errorHandler
}